package club.banyuan.api.Demo1;

/**
 * @author edz
 * @version 1.0
 * @date 2020/11/26 下午7:08
 */
public class work2 {
    private String st = "";

    public void append(String str) {
        st += str;
    }

    void append(char str) {
        st += str;
    }

    String toString(String st) {
        return st;
    }

    public void clear() {
        st = "";
    }

    String reverse(String st) {
        char[] chars = st.toCharArray();
        char[] newChars = new char[chars.length];
        for (int i = 0; i < chars.length; i++) {
            newChars[chars.length - 1 - i] = chars[i];
            st = new String(newChars);
        }
        return st;
    }

    public String reverse(int from, int to) {
        if (from > to || to > st.length()) {
            System.out.println("输入位置不对");
            return null;
        }
        String str1 = st.substring(0, from);
        String str2 = st.substring(from, to);
        String str3 = st.substring(to, st.length());
        st = str1 + str2 + str3;
        return st;
    }
}
